#!/usr/bin/env perl
use warnings;
use strict;

use List::Util qw/sum/;

my @depth;
my $n;
my $repeat=3;
my @allel_depth;
my @af;
my $depth=0;

while (<>) {
	chomp;
	@depth = split /\t/;
    $n=($#depth+1)/$repeat;
    @af=();
    $depth=0;
    foreach my $i (0..$n-1) {
        
        if ($depth[$i] eq "0/1") {
            @allel_depth=  split /,/, $depth[$i+$n];
            $depth+=$allel_depth[1];
            push(@af, $allel_depth[1]/$depth[$i+2*$n]);
        }elsif ($depth[$i] eq "1/1") {
            @allel_depth=  split /,/, $depth[$i+$n];
            $depth+= sum(@allel_depth);
            push(@af, sum(@allel_depth)/$depth[$i+2*$n]);
        }elsif ($depth[$i] =~ /1\/[23]/) {
            @allel_depth=  split /,/, $depth[$i+$n];
            $depth+= $allel_depth[0];
            push(@af, $allel_depth[0]/$depth[$i+2*$n]);
        }
    }
    printf "%.2f\t%d\n", sum(@af)/($#af+1), $depth;
}

